<template>
  <!-- <var-app-bar class="shadow-none mb-2" title="上课记录..." /> -->
  <h5 class="my-2 text-neutral-300">课程日期</h5>
   <var-app-bar class="">{{ `同学！你目前共上${list.length}节课哦！继续努力！` }}</var-app-bar>
    <var-date-picker   v-model="date" :allowed-dates="allowedDates" @change="toHistoryList"/>
  
</template>

<script setup>
import { ref, onMounted } from "vue";
import { postData } from "@/utils/api";
import { useRouter } from "vue-router";
import { loginStore } from "@/store/user";
const cusRouter = useRouter();
const store = loginStore();
const list = ref([]);
const date = ref("");
let user = "";
if (store.getUserInfo?.userInfo == undefined) {
  user = store.getUserInfo;
} else {
  user = JSON.parse(store.getUserInfo?.userInfo);
}
onMounted(() => {
  getLogDate();
  
});
const getLogDate = async () => {
  await postData("config/test/getLogDate", {
    classroomId: user.classRoomId,
    studentId: user.id,
  }).then((res) => {
    //console.log(res);
    const { data } = res.data;
    const dates = [];
    data.forEach(ite => {
      
     let strs = delZero(ite.schooltime);
     dates.push(strs)
    });
    list.value = dates;
    //console.log(list.value);
  });
};

const delZero =(str)=>{
  let strArray  = str.split("-");
  let strVal = strArray[2];
  if(strVal[0] == "0"){
    strArray[2] = strVal.slice(1);
  }else{
    strArray[2] = strVal;
  }
  return strArray.join("-");
}


const toHistoryList = (val) => {
  console.log(val)
  cusRouter.push({
    name: "historys",
    state: { schooltime: val },
  });
};

const allowedDates = val => list.value.indexOf(val)>-1
//{
  // console.log(val.split('-')[2])
 // console.log( list.value.indexOf(val)>-1)
 
 //console.log(parseInt(val.split('-')[2], 10) % 2 === 1)
 
//}; 
</script>

<style scoped>
:deep(.var-date-picker__title){
  display: none;
}
:deep(.var-day-picker__button--usable:not(.var-day-picker__button--disabled)){
  border: none;
  color: #fff;
  background-color: #3a7afe;
  box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2),0 2px 2px 0 rgba(0, 0, 0, 0.14),0 1px 5px 0 rgba(0, 0, 0, 0.12);
}
:deep(.var-app-bar__title){
  font-size: initial;
}

</style>
